<?php

/**
 * This is the model class for table "inspection".
 *
 * The followings are the available columns in table 'inspection':
 * @property integer $id
 * @property string $date_investigate
 * @property integer $establishment_id
 *
 * The followings are the available model relations:
 * @property AlarmSystem[] $alarmSystems
 * @property AutomaticFireSuppressionSystem[] $automaticFireSuppressionSystems
 * @property BuildingConstruction[] $buildingConstructions
 * @property BuildingServiceEquipment[] $buildingServiceEquipments
 * @property Classification[] $classifications
 * @property EmergencyLight[] $emergencyLights
 * @property ExitDetail[] $exitDetails
 * @property ExitSign[] $exitSigns
 * @property FireWall[] $fireWalls
 * @property FirstAidFireProtectionEquipment[] $firstAidFireProtectionEquipments
 * @property GeneralInformation[] $generalInformations
 * @property HazardousArea[] $hazardousAreas
 * @property Establishment $establishment
 * @property Inspector[] $inspectors
 * @property OperatingFeature[] $operatingFeatures
 * @property OtherSafetyFeature[] $otherSafetyFeatures
 * @property ProtectionOfVerticalOpening[] $protectionOfVerticalOpenings
 * @property Pump[] $pumps
 * @property SectionalOccupancy[] $sectionalOccupancies
 * @property StandpipeSystem[] $standpipeSystems
 * @property UndergroundTank[] $undergroundTanks
 * @property VentPipe[] $ventPipes
 * @property WarningOrSafetySign[] $warningOrSafetySigns
 */
class Inspection extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Inspection the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'inspection';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('establishment_id', 'required'),
			array('establishment_id', 'numerical', 'integerOnly'=>true),
			array('date_investigate', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, date_investigate, establishment_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'alarmSystems' => array(self::HAS_MANY, 'AlarmSystem', 'inspection_id'),
			'automaticFireSuppressionSystems' => array(self::HAS_MANY, 'AutomaticFireSuppressionSystem', 'inspection_id'),
			'buildingConstructions' => array(self::HAS_MANY, 'BuildingConstruction', 'inspection_id'),
			'buildingServiceEquipments' => array(self::HAS_MANY, 'BuildingServiceEquipment', 'inspection_id'),
			'classifications' => array(self::HAS_MANY, 'Classification', 'inspection_id'),
			'emergencyLights' => array(self::HAS_MANY, 'EmergencyLight', 'inspection_id'),
			'exitDetails' => array(self::HAS_MANY, 'ExitDetail', 'inspection_id'),
			'exitSigns' => array(self::HAS_MANY, 'ExitSign', 'inspection_id'),
			'fireWalls' => array(self::HAS_MANY, 'FireWall', 'inspection_id'),
			'firstAidFireProtectionEquipments' => array(self::HAS_MANY, 'FirstAidFireProtectionEquipment', 'inspection_id'),
			'generalInformations' => array(self::HAS_MANY, 'GeneralInformation', 'inspection_id'),
			'hazardousAreas' => array(self::HAS_MANY, 'HazardousArea', 'inspection_id'),
			'establishment' => array(self::BELONGS_TO, 'Establishment', 'establishment_id'),
			'inspectors' => array(self::HAS_MANY, 'Inspector', 'inspection_id'),
			'operatingFeatures' => array(self::HAS_MANY, 'OperatingFeature', 'inspection_id'),
			'otherSafetyFeatures' => array(self::HAS_MANY, 'OtherSafetyFeature', 'inspection_id'),
			'protectionOfVerticalOpenings' => array(self::HAS_MANY, 'ProtectionOfVerticalOpening', 'inspection_id'),
			'pumps' => array(self::HAS_MANY, 'Pump', 'inspection_id'),
			'sectionalOccupancies' => array(self::HAS_MANY, 'SectionalOccupancy', 'inspection_id'),
			'standpipeSystems' => array(self::HAS_MANY, 'StandpipeSystem', 'inspection_id'),
			'undergroundTanks' => array(self::HAS_MANY, 'UndergroundTank', 'inspection_id'),
			'ventPipes' => array(self::HAS_MANY, 'VentPipe', 'inspection_id'),
			'warningOrSafetySigns' => array(self::HAS_MANY, 'WarningOrSafetySign', 'inspection_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'date_investigate' => 'Date Investigate',
			'establishment_id' => 'Establishment',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('date_investigate',$this->date_investigate,true);
		$criteria->compare('establishment_id',$this->establishment_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}